const axios = require('axios')
const fs = require('fs')
const util = require('util');
const appendFile = async (url,type='js')=>{
    const posStart = url.indexOf('/',8)
    const posEnd = url.lastIndexOf('/')
    const path = url.substring(posStart,posEnd)
    let res = await axios.get(url)
     console.log(url,posStart,posEnd,path)
    const mkdir = util.promisify(fs.mkdir)
    const writeFile = util.promisify(fs.writeFile)
    try{
        await mkdir('./static/'+type+'/'+path, { recursive: true });
        await writeFile('./static/'+type+'/'+path+'/'+url.substr(posEnd+1), res.data)
    }catch (e) {
        console.log(e)
    }
}
module.exports = {
    appendFile
}
